import { ajax } from '@/utils'

import {
  AddAccountReq,
  GetAccountListRes,
  GetAccountPageReq,
  Permission,
  ResetPasswordReq
} from './accountTypes'

export default {
  /** 分页查询 */
  getAccountList(data: GetAccountPageReq): Promise<GetAccountListRes> {
    return ajax.post('/yswy-zy-permission/user/listByPage', data)
  },
  /** 修改密码 */
  resetPassword({ id, password }: ResetPasswordReq) {
    return ajax.post(`/yswy-zy-permission/user/resetPassword/${id}/${password}`)
  },
  /** 新增用户 */
  addAccount(data: AddAccountReq) {
    return ajax.post('/yswy-zy-permission/user/add', data)
  },
  /** 编辑用户 */
  editAccount(data: AddAccountReq) {
    return ajax.post('/yswy-zy-permission/user/edit', data)
  },
  /** 禁用账号 */
  disableAccount(id, deleteFlag) {
    return ajax.post(`/yswy-zy-permission/user/disable/${id}/${deleteFlag}`)
  },
  /**获取权限 */
  getPermission(userId: string): Promise<Permission[]> {
    return ajax.get(
      `/yswy-zy-permission/permission/getPermission?userId=${userId}`
    )
  },
  /**获取所有权限 */
  getPermissionAll(): Promise<Permission[]> {
    return ajax.get(`/yswy-zy-permission/permission/getPermissionAll`)
  }
}
